/** for Dimension */
import java.awt.Dimension;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
/** for ChangeEvent */
import javax.swing.event.ChangeEvent;

/** for ChangeListener */
import javax.swing.event.ChangeListener;

/** for Font */
import java.awt.Font;

/** for ActionEvent */
import java.awt.event.ActionEvent;

/** for ActionListener */
import java.awt.event.ActionListener;

/** for Color */
import java.awt.Color;

/** for ArrayList */
import java.util.ArrayList;
import java.util.List;

/**
 * This is a class to handle the item panel in JPanel
 * @author Code Traders
 * @version 1.0
 */
public class ItemPanel extends JPanel
implements MainPanel, ActionListener, ChangeListener {
	
	/**
	 * serialVersionUID for the ItemPanel class
	 */
	private static final long serialVersionUID = 7302230523128367425L;
	
	/**
	 * Width and height for the JPanel
	 */
	private static final int WIDTH = 640, HEIGHT = 252;
	
	/** for 17**/
	private static final int SEVENTEEN = 17;
	
	/** for 155**/
	private static final int O_HUN_F_F = 155;
	
	/** for 23**/
	private static final int TWENTYTHREE = 23;
	
	/** for 111**/
	private static final int O_HUN_O_O = 111;
	
	/** for 321**/
	private static final int T_HUN_T_O = 321;
	
	/** for 67**/
	private static final int SIXTYSEVEN = 67;
	
	/** for 494**/
	private static final int F_HUN_N_F = 494;
	
	/** for 72**/
	private static final int SEVENTYTWO = 72;
	
	/** for 14**/
	private static final int FOURTEEN = 14;
	
	/** for 126**/
	private static final int O_HUN_T_S = 126;
	
	/** for 61**/
	private static final int SIXTYONE = 61;
	
	/** for 140**/
	private static final int O_HUN_F_Z = 140;
	
	/** for 96**/
	private static final int NINETYSIX = 96;
	
	/** for 131**/
	private static final int O_HUN_T_O = 131;
	
	/** for 274**/
	private static final int T_HUN_S_F = 274;
	
	/** for 60**/
	private static final int SIXTY = 60;
	
	/** for 135**/
	private static final int O_HUN_T_F = 135;
	
	/** for 95**/
	private static final int NINETYFIVE = 95;
	
	/** for 441**/
	private static final int F_HUN_F_O = 441;
	
	/** for 59**/
	private static final int FIFTYNINE = 59;
	
	/** for 167**/
	private static final int O_HUN_S_S = 167;
	
	/** for 94**/
	private static final int NINETYFOUR = 94;
	
	/** for 129**/
	private static final int O_HUN_T_N = 129;
	
	/** for 178**/
	private static final int O_HUN_S_E = 178;
	
	/** for 164**/
	private static final int O_HUN_S_F = 164;
	
	/** for 199**/
	private static final int O_HUN_N_N = 199;
	
	/** for 148**/
	private static final int O_HUN_F_E = 148;
	
	/** for 296**/
	private static final int T_HUN_N_S = 296;
	
	/** for 185**/
	private static final int O_HUN_E_F = 185;
	
	/** for 367**/
	private static final int T_HUN_S_S = 367;
	
	/** for 40**/
	private static final int FORTY = 40;
	
	/** for 226**/
	private static final int T_HUN_T_S = 226;
	
	/** for 18**/
	private static final int EIGHTTEEN = 18;
	
	/** for 101**/
	private static final int O_HUN_O = 101;
	
	/** for 120**/
	private static final int O_HUN_T_Z = 120;
	
	/** for 142**/
	private static final int O_HUN_F_T = 142;
	
	/** for 69**/
	private static final int SIXTYNINE = 69;
	
	/** for 212**/
	private static final int T_HUN_O_T = 212;
	
	/** for 197**/
	private static final int O_HUN_NINE_S = 197;
	
	/** for 54**/
	private static final int FIFTYFOUR = 54;
	
	/** for 28**/
	private static final int TWENTYEIGHT = 28;
	
	/** for 243**/
	private static final int T_HUN_F_T = 243;
	
	/** for 64**/
	private static final int SIXTYFOUR = 64;
	
	/** for 16**/
	private static final int SIXTEEN = 16;
	
	/** for 99**/
	private static final int NINETYNINE = 99;
	
	/** for 254**/
	private static final int T_HUN_F_F = 254;
	
	/** for 132**/
	private static final int O_HUN_T_T = 132;
	
	/** for 404**/
	private static final int F_HUN_Z_F = 404;
	
	/** for 63**/
	private static final int SIXTYTHREE = 63;
	
	/** for 425**/
	private static final int F_HUN_T_F = 425;
	
	/** for 98**/
	private static final int NINETYEIGHT = 98;
	
	/** for 612**/
	private static final int S_HUN_O_T = 612;
	
	/** for 611**/
	private static final int S_HUN_O_O = 611;
	
	/** for 618**/
	private static final int S_HUN_O_E = 618;
	
	/** for 578**/
	private static final int F_HUN_S_E = 578;
	
	/** for 203**/
	private static final int T_HUN_Z_T = 203;
	
	/** for 307**/
	private static final int T_HUN_Z_S = 307;
	
	/** for 112**/
	private static final int O_HUN_O_T = 112;
	
	/** for 2**/
	private static final int TWO = 2;
	
	/** for 3**/
	private static final int THREE = 3;
	
	/** for 4**/
	private static final int FOUR = 4;
	
	/** for FIVE **/
	private static final int FIVE = 5;

	/** for SIX **/
	private static final int SIX = 6;
	
	/** for SEVEN **/
	private static final int SEVEN = 7;
	
	/** for EIGHT **/
	private static final int EIGHT = 8;
	
	/** for NINE **/
	private static final int NINE = 9;
	
	/** for 591 **/
	private static final int F_HUN_N_O = 591;
	
	/**for 62 **/
	private static final int SIXTYTWO = 62;
	
	/**
	 * current ship
	 */
	private final Ship ship;
	
	/**
	 * current ItemMarketPlace
	 */
	private ItemMarketPlace imp;
	
	/**
	 * current BottomPanel
	 */
	private BottomPanel bottom;
	
	/**
	 * JLabels on the ItemPanel
	 */
	private final JLabel pulselbl, beamlbl, militarylbl,
	energylbl, reflectivelbl, eclbl, navlbl,
	arlbl, targetlbl, cloaklbl, lblTotal;
	
	/**
	 * fuelSpinner
	 */
	private final JSpinner fuelSpinner;
	
	/**
	 * JRadioButtons on the ItemPanel
	 */
	private final JRadioButton rdbtnFlea, rdbtnGnat,
	rdbtnFirefly, rdbtnMosquito, rdbtnBumblebee, rdbtnFuel;
	
	/**
	 * ButtonGroup for the JRadioButtons
	 */
	private final ButtonGroup itemButtonGroup;
	
	/**
	 * ArrayList holding the commands for the ships
	 */
	private final List<String> shipCommands = new ArrayList<String>();
	
	/**
	 * ArrayList holding the commands for the weapons
	 */
	private final List<String> weaponCommands = new ArrayList<String>();
	
	/**
	 * ArrayList holding the commands for the shields
	 */
	private final List<String> shieldCommands = new ArrayList<String>();
	
	/**
	 * ArrayList holding the commands for the gadgets
	 */
	private final List<String> gadgetCommands = new ArrayList<String>();
	
	/**
	 * Create the panel.
	 */
	public ItemPanel() {
		super.setPreferredSize(new Dimension(WIDTH, HEIGHT));
		super.setOpaque(false);
		super.setLayout(null);
		
		shipCommands.add("flea");
		shipCommands.add("gnat");
		shipCommands.add("firefly");
		shipCommands.add("mosquito");
		shipCommands.add("bumblebee");
		weaponCommands.add("pulse");
		weaponCommands.add("beam");
		weaponCommands.add("military");
		shieldCommands.add("energy");
		shieldCommands.add("reflective");
		gadgetCommands.add("ec");
		gadgetCommands.add("nav");
		gadgetCommands.add("ar");
		gadgetCommands.add("target");
		gadgetCommands.add("cloak");
		
		final JLabel lblWeapons = new JLabel("Weapons");
		lblWeapons.setForeground(Color.YELLOW);
		lblWeapons.setFont(new Font("Segoe UI Semibold", Font.BOLD, SEVENTEEN));
		lblWeapons.setBounds(O_HUN_F_F, TWENTYTHREE, O_HUN_O_O, TWENTYTHREE);
		super.add(lblWeapons);
		
		final JLabel lblShields = new JLabel("Shields");
		lblShields.setForeground(Color.YELLOW);
		lblShields.setFont(new Font("Segoe UI Semibold", Font.BOLD, SEVENTEEN));
		lblShields.setBounds(T_HUN_T_O, TWENTYTHREE, SIXTYSEVEN, TWENTYTHREE);
		super.add(lblShields);
		
		final JLabel lblGadgets = new JLabel("Gadgets");
		lblGadgets.setForeground(Color.YELLOW);
		lblGadgets.setFont(new Font("Segoe UI Semibold", Font.BOLD, SEVENTEEN));
		lblGadgets.setBounds(F_HUN_N_F, TWENTYTHREE, SEVENTYTWO, TWENTYTHREE);
		super.add(lblGadgets);
		
		final JRadioButton rdbtnPulseLaser = new JRadioButton("Pulse Laser");
		rdbtnPulseLaser.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnPulseLaser.setForeground(Color.YELLOW);
		rdbtnPulseLaser.setBounds(O_HUN_T_S, SIXTYONE, O_HUN_F_Z, TWENTYTHREE);
		rdbtnPulseLaser.setActionCommand("pulse");
		rdbtnPulseLaser.addActionListener(this);
		rdbtnPulseLaser.setOpaque(false);
		super.add(rdbtnPulseLaser);
		
		final JRadioButton rdbtnBeamLaser = new JRadioButton("Beam Laser");
		rdbtnBeamLaser.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnBeamLaser.setForeground(Color.YELLOW);
		rdbtnBeamLaser.setBounds(O_HUN_T_S, NINETYSIX, O_HUN_F_Z, TWENTYTHREE);
		rdbtnBeamLaser.setActionCommand("beam");
		rdbtnBeamLaser.addActionListener(this);
		rdbtnBeamLaser.setOpaque(false);
		super.add(rdbtnBeamLaser);
		
		final JRadioButton rdbtnMilitaryLaser = new JRadioButton("Military Laser");
		rdbtnMilitaryLaser.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnMilitaryLaser.setForeground(Color.YELLOW);
		rdbtnMilitaryLaser.setBounds(O_HUN_T_S, O_HUN_T_O, O_HUN_F_Z, TWENTYTHREE);
		rdbtnMilitaryLaser.setActionCommand("military");
		rdbtnMilitaryLaser.addActionListener(this);
		rdbtnMilitaryLaser.setOpaque(false);
		super.add(rdbtnMilitaryLaser);
		
		/*
		ButtonGroup weaponButtonGroup = new ButtonGroup();
		weaponButtonGroup.add(rdbtnPulseLaser);
		weaponButtonGroup.add(rdbtnBeamLaser);
		weaponButtonGroup.add(rdbtnMilitaryLaser);
		*/
		
		final JRadioButton rdbtnEnergyShield = new JRadioButton("Energy Shield");
		rdbtnEnergyShield.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnEnergyShield.setForeground(Color.YELLOW);
		rdbtnEnergyShield.setBounds(T_HUN_S_F, SIXTY, O_HUN_T_F, TWENTYTHREE);
		rdbtnEnergyShield.setActionCommand("energy");
		rdbtnEnergyShield.addActionListener(this);
		rdbtnEnergyShield.setOpaque(false);
		super.add(rdbtnEnergyShield);
		
		final JRadioButton rdbtnReflectiveShield = new JRadioButton("Reflective Shield");
		rdbtnReflectiveShield.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnReflectiveShield.setForeground(Color.YELLOW);
		rdbtnReflectiveShield.setBounds(T_HUN_S_F, NINETYFIVE, O_HUN_F_F, TWENTYTHREE);
		rdbtnReflectiveShield.setActionCommand("reflective");
		rdbtnReflectiveShield.addActionListener(this);
		rdbtnReflectiveShield.setOpaque(false);
		super.add(rdbtnReflectiveShield);
		
		/*
		ButtonGroup shieldButtonGroup = new ButtonGroup();
		shieldButtonGroup.add(rdbtnEnergyShield);
		shieldButtonGroup.add(rdbtnReflectiveShield);
		*/
		
		final JRadioButton rdbtnExtraCargo = new JRadioButton("5 Extra Cargo Bays");
		rdbtnExtraCargo.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnExtraCargo.setForeground(Color.YELLOW);
		rdbtnExtraCargo.setBounds(F_HUN_F_O, FIFTYNINE, O_HUN_S_S, TWENTYTHREE);
		rdbtnExtraCargo.setActionCommand("ec");
		rdbtnExtraCargo.addActionListener(this);
		rdbtnExtraCargo.setOpaque(false);
		super.add(rdbtnExtraCargo);
		
		final JRadioButton rdbtnNavigationSystem = new JRadioButton("Navigation System");
		rdbtnNavigationSystem.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnNavigationSystem.setForeground(Color.YELLOW);
		rdbtnNavigationSystem.setBounds(F_HUN_F_O, NINETYFOUR, O_HUN_S_S, TWENTYTHREE);
		rdbtnNavigationSystem.setActionCommand("nav");
		rdbtnNavigationSystem.addActionListener(this);
		rdbtnNavigationSystem.setOpaque(false);
		super.add(rdbtnNavigationSystem);
		
		final JRadioButton rdbtnAutorepairSystem = new JRadioButton("Auto-Repair System");
		rdbtnAutorepairSystem.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnAutorepairSystem.setForeground(Color.YELLOW);
		rdbtnAutorepairSystem.setBounds(F_HUN_F_O, O_HUN_T_N, O_HUN_S_E, TWENTYTHREE);
		rdbtnAutorepairSystem.setActionCommand("ar");
		rdbtnAutorepairSystem.addActionListener(this);
		rdbtnAutorepairSystem.setOpaque(false);
		super.add(rdbtnAutorepairSystem);
		
		final JRadioButton rdbtnTargetSystem = new JRadioButton("Target System");
		rdbtnTargetSystem.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnTargetSystem.setForeground(Color.YELLOW);
		rdbtnTargetSystem.setBounds(F_HUN_F_O, O_HUN_S_F, O_HUN_F_Z, TWENTYTHREE);
		rdbtnTargetSystem.setActionCommand("target");
		rdbtnTargetSystem.addActionListener(this);
		rdbtnTargetSystem.setOpaque(false);
		super.add(rdbtnTargetSystem);
		
		final JRadioButton rdbtnCloakingDevice = new JRadioButton("Cloaking Device");
		rdbtnCloakingDevice.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnCloakingDevice.setForeground(Color.YELLOW);
		rdbtnCloakingDevice.setBounds(F_HUN_F_O, O_HUN_N_N, O_HUN_F_E, TWENTYTHREE);
		rdbtnCloakingDevice.setActionCommand("cloak");
		rdbtnCloakingDevice.addActionListener(this);
		rdbtnCloakingDevice.setOpaque(false);
		super.add(rdbtnCloakingDevice);
		
		/*
		ButtonGroup gadgetButtonGroup = new ButtonGroup();
		gadgetButtonGroup.add(rdbtnExtraCargo);
		gadgetButtonGroup.add(rdbtnNavigationSystem);
		gadgetButtonGroup.add(rdbtnAutorepairSystem);
		gadgetButtonGroup.add(rdbtnTargetSystem);
		gadgetButtonGroup.add(rdbtnCloakingDevice);
		*/
		
		final JButton buyButton = new JButton("");
		buyButton.setContentAreaFilled(false);
		buyButton.setBorderPainted(false);
		buyButton.setPressedIcon(new ImageIcon
				(ItemPanel.class.getResource("/image/buyItem_pressed.png")));
		buyButton.setOpaque(false);
		buyButton.setSelectedIcon(new ImageIcon
				(ItemPanel.class.getResource("/image/buyItem_pressed.png")));
		buyButton.setIcon(new ImageIcon
				(ItemPanel.class.getResource("/image/buyItem.png")));
		buyButton.setForeground(Color.YELLOW);
		buyButton.setBounds(T_HUN_N_S, O_HUN_E_F, FIFTYNINE, SIXTYSEVEN);
		buyButton.setActionCommand("buy");
		buyButton.addActionListener(this);
		super.add(buyButton);
		
		final JButton sellButton = new JButton("");
		sellButton.setBorderPainted(false);
		sellButton.setContentAreaFilled(false);
		sellButton.setPressedIcon(new ImageIcon
				(ItemPanel.class.getResource("/image/sellItem_pressed.png")));
		sellButton.setSelectedIcon(new ImageIcon
				(ItemPanel.class.getResource("/image/sellItem_pressed.png")));
		sellButton.setOpaque(false);
		sellButton.setIcon(new ImageIcon
				(ItemPanel.class.getResource("/image/sellItem.png")));
		sellButton.setForeground(Color.YELLOW);
		sellButton.setBounds(T_HUN_S_S, O_HUN_E_F, FIFTYNINE, SIXTYSEVEN);
		sellButton.setActionCommand("sell");
		sellButton.addActionListener(this);
		super.add(sellButton);
		
		final JLabel lblShips = new JLabel("Ships");
		lblShips.setForeground(Color.YELLOW);
		lblShips.setFont(new Font("Segoe UI Semibold", Font.BOLD, SEVENTEEN));
		lblShips.setBounds(FORTY, TWENTYTHREE, T_HUN_T_S, TWENTYTHREE);
		super.add(lblShips);
		
		rdbtnFlea = new JRadioButton("Flea");
		rdbtnFlea.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnFlea.setForeground(Color.YELLOW);
		rdbtnFlea.setBounds(EIGHTTEEN, SIXTY, O_HUN_O, TWENTYTHREE);
		rdbtnFlea.setActionCommand("flea");
		rdbtnFlea.addActionListener(this);
		rdbtnFlea.setOpaque(false);
		super.add(rdbtnFlea);
		
		rdbtnGnat = new JRadioButton("Gnat");
		rdbtnGnat.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnGnat.setForeground(Color.YELLOW);
		rdbtnGnat.setBounds(EIGHTTEEN, NINETYSIX, O_HUN_O, TWENTYTHREE);
		rdbtnGnat.setActionCommand("gnat");
		rdbtnGnat.addActionListener(this);
		rdbtnGnat.setOpaque(false);
		super.add(rdbtnGnat);
		
		rdbtnFirefly = new JRadioButton("Firefly");
		rdbtnFirefly.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnFirefly.setForeground(Color.YELLOW);
		rdbtnFirefly.setBounds(EIGHTTEEN, O_HUN_T_O, O_HUN_O, TWENTYTHREE);
		rdbtnFirefly.setActionCommand("firefly");
		rdbtnFirefly.addActionListener(this);
		rdbtnFirefly.setOpaque(false);
		super.add(rdbtnFirefly);
		
		rdbtnMosquito = new JRadioButton("Mosquito");
		rdbtnMosquito.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnMosquito.setForeground(Color.YELLOW);
		rdbtnMosquito.setBounds(EIGHTTEEN, O_HUN_S_F, O_HUN_O, TWENTYTHREE);
		rdbtnMosquito.setActionCommand("mosquito");
		rdbtnMosquito.addActionListener(this);
		rdbtnMosquito.setOpaque(false);
		super.add(rdbtnMosquito);
		
		rdbtnBumblebee = new JRadioButton("Bumblebee");
		rdbtnBumblebee.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnBumblebee.setForeground(Color.YELLOW);
		rdbtnBumblebee.setBounds(EIGHTTEEN, O_HUN_N_N, O_HUN_T_Z, TWENTYTHREE);
		rdbtnBumblebee.setActionCommand("bumblebee");
		rdbtnBumblebee.addActionListener(this);
		rdbtnBumblebee.setOpaque(false);
		super.add(rdbtnBumblebee);
		
		/*
		ButtonGroup shipButtonGroup = new ButtonGroup();
		shipButtonGroup.add(rdbtnFlea);
		shipButtonGroup.add(rdbtnGnat);
		shipButtonGroup.add(rdbtnFirefly);
		shipButtonGroup.add(rdbtnMosquito);
		shipButtonGroup.add(rdbtnBumblebee);
		*/
		
		rdbtnFuel = new JRadioButton("Fuel");
		rdbtnFuel.setForeground(Color.YELLOW);
		rdbtnFuel.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		rdbtnFuel.setBounds(O_HUN_F_T, O_HUN_N_N, SIXTYNINE, TWENTYTHREE);
		rdbtnFuel.setActionCommand("fuel");
		rdbtnFuel.addActionListener(this);
		rdbtnFuel.setOpaque(false);
		super.add(rdbtnFuel);
		
		itemButtonGroup = new ButtonGroup();
		itemButtonGroup.add(rdbtnFlea);
		itemButtonGroup.add(rdbtnGnat);
		itemButtonGroup.add(rdbtnFirefly);
		itemButtonGroup.add(rdbtnMosquito);
		itemButtonGroup.add(rdbtnBumblebee);
		itemButtonGroup.add(rdbtnPulseLaser);
		itemButtonGroup.add(rdbtnBeamLaser);
		itemButtonGroup.add(rdbtnMilitaryLaser);
		itemButtonGroup.add(rdbtnEnergyShield);
		itemButtonGroup.add(rdbtnReflectiveShield);
		itemButtonGroup.add(rdbtnExtraCargo);
		itemButtonGroup.add(rdbtnNavigationSystem);
		itemButtonGroup.add(rdbtnAutorepairSystem);
		itemButtonGroup.add(rdbtnTargetSystem);
		itemButtonGroup.add(rdbtnCloakingDevice);
		itemButtonGroup.add(rdbtnFuel);
		
		fuelSpinner = new JSpinner();
		fuelSpinner.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		fuelSpinner.setForeground(Color.YELLOW);
		fuelSpinner.setBounds(T_HUN_O_T, O_HUN_NINE_S, FIFTYFOUR, TWENTYEIGHT);
		fuelSpinner.setEditor(new JSpinner.DefaultEditor(fuelSpinner)); // sets the textfield of the spinner to not be editable
		fuelSpinner.setEnabled(false);
		fuelSpinner.addChangeListener(this);
		fuelSpinner.setOpaque(false);
		super.add(fuelSpinner);
		
		pulselbl = new JLabel("(0)");
		pulselbl.setForeground(Color.YELLOW);
		pulselbl.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		pulselbl.setBounds(T_HUN_F_T, SIXTYFOUR, TWENTYTHREE, SIXTEEN);
		super.add(pulselbl);
		
		beamlbl = new JLabel("(0)");
		beamlbl.setForeground(Color.YELLOW);
		beamlbl.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		beamlbl.setBounds(T_HUN_F_T, NINETYNINE, TWENTYTHREE, SIXTEEN);
		super.add(beamlbl);
		
		militarylbl = new JLabel("(0)");
		militarylbl.setForeground(Color.YELLOW);
		militarylbl.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		militarylbl.setBounds(T_HUN_F_F, O_HUN_T_T, TWENTYTHREE, SIXTEEN);
		super.add(militarylbl);
		
		energylbl = new JLabel("(0)");
		energylbl.setForeground(Color.YELLOW);
		energylbl.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		energylbl.setBounds(F_HUN_Z_F, SIXTYTHREE, TWENTYTHREE, SIXTEEN);
		super.add(energylbl);
		
		reflectivelbl = new JLabel("(0)");
		reflectivelbl.setForeground(Color.YELLOW);
		reflectivelbl.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		reflectivelbl.setBounds(F_HUN_T_F, NINETYEIGHT, TWENTYTHREE, SIXTEEN);
		super.add(reflectivelbl);
		
		eclbl = new JLabel("(0)");
		eclbl.setForeground(Color.YELLOW);
		eclbl.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		eclbl.setBounds(S_HUN_O_T, SIXTYTWO, TWENTYTHREE, SIXTEEN);
		super.add(eclbl);
		
		navlbl = new JLabel("(0)");
		navlbl.setForeground(Color.YELLOW);
		navlbl.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		navlbl.setBounds(S_HUN_O_O, NINETYEIGHT, TWENTYTHREE, SIXTEEN);
		super.add(navlbl);
		
		arlbl = new JLabel("(0)");
		arlbl.setForeground(Color.YELLOW);
		arlbl.setFont(new Font("Dialog", Font.BOLD, FOURTEEN));
		arlbl.setBounds(S_HUN_O_E, O_HUN_T_T, TWENTYTHREE, SIXTEEN);
		super.add(arlbl);
		
		targetlbl = new JLabel("(0)");
		targetlbl.setForeground(Color.YELLOW);
		targetlbl.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		targetlbl.setBounds(F_HUN_S_E, O_HUN_S_S, TWENTYTHREE, SIXTEEN);
		super.add(targetlbl);
		
		cloaklbl = new JLabel("(0)");
		cloaklbl.setForeground(Color.YELLOW);
		cloaklbl.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		cloaklbl.setBounds(F_HUN_N_O, T_HUN_Z_T, TWENTYTHREE, SIXTEEN);
		super.add(cloaklbl);
		
		lblTotal = new JLabel("Total: 0");
		lblTotal.setForeground(Color.YELLOW);
		lblTotal.setHorizontalAlignment(SwingConstants.RIGHT);
		lblTotal.setFont(new Font("Segoe UI Semibold", Font.BOLD, FOURTEEN));
		lblTotal.setBounds(T_HUN_Z_S, O_HUN_S_F, O_HUN_O_T, SIXTEEN);
		super.add(lblTotal);
		
		ship = (Ship) Singleton.INSTANCE.get("ship"); // Singleton
	}
	
	/**
	 * to update item panel
	 */
	@Override
	public void update() {
		// update the amount of items in the ship
		final int[] numberOfItems = ship.numberOfItems();
		pulselbl.setText("(" + numberOfItems[0] + ")");
		beamlbl.setText("(" + numberOfItems[1] + ")");
		militarylbl.setText("(" + numberOfItems[TWO] + ")");
		energylbl.setText("(" + numberOfItems[THREE] + ")");
		reflectivelbl.setText("(" + numberOfItems[FOUR] + ")");
		eclbl.setText("(" + numberOfItems[FIVE] + ")");
		navlbl.setText("(" + numberOfItems[SIX] + ")");
		arlbl.setText("(" + numberOfItems[SEVEN] + ")");
		targetlbl.setText("(" + numberOfItems[EIGHT] + ")");
		cloaklbl.setText("(" + numberOfItems[NINE] + ")");
		
		// limits the maximum value of the fuelSpinner to the maximum allowed potential fuel to be added
		fuelSpinner.setModel(new SpinnerNumberModel(0, 0,
				Math.round(new Float(ship.getShipType().getMaxFuel()
						- ship.getFuel())), 1));
		
		// update the price for the fuel with the updated amount
		if (rdbtnFuel.isSelected()) {
			lblTotal.setText("Total: " + ship.getShipType().getFuelCost()
					* (int) fuelSpinner.getValue());
		}
		
		// disables the radiobutton, for the list of ships, that matches the current ship type
		rdbtnFlea.setEnabled(!ship.getShipType().equals(Ships.FLEA));
		rdbtnGnat.setEnabled(!ship.getShipType().equals(Ships.GNAT));
		rdbtnFirefly.setEnabled(!ship.getShipType().equals(Ships.FIREFLY));
		rdbtnMosquito.setEnabled(!ship.getShipType().equals(Ships.MOSQUITO));
		rdbtnBumblebee.setEnabled(!ship.getShipType().equals(Ships.BUMBLEBEE));
		
		// updates the BottomPanel
		bottom.updateBottomPanel("store");
	}
	
	/**
	 * to set item to market place
	 * @param imp
	 */
	public void setItemMarketPlace(ItemMarketPlace imp) {
		this.imp = imp;
	}
	
	/**
	 * to set the bottom panel
	 * @param bp
	 */
	public void setBottomPanel(BottomPanel bp) {
		this.bottom = bp;
	}
	
	/**
	 * to action performed
	 * @param e
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() instanceof JRadioButton) {
			fuelSpinner.setEnabled(e.getSource().equals(rdbtnFuel));
			radioButtonActionPerformed();
		} else if (e.getSource() instanceof JButton) {
			if (itemButtonGroup.getSelection() == null) return;
			final String ac = itemButtonGroup.getSelection().getActionCommand();
			if (e.getActionCommand().equals("buy")) {
				buyButtonActionPerformed(ac);
			} else if (e.getActionCommand().equals("sell")) {
				sellButtonActionPerformed(ac);
			}
			itemButtonGroup.clearSelection();
			fuelSpinner.setValue(0);
		}
		update();
	}
	
	/**
	 * for radio Button Action Performed
	 */
	private void radioButtonActionPerformed() {
		// update the price for the selected item
		final String ac = itemButtonGroup.getSelection().getActionCommand();
		String str = "Total: ";
		if (shipCommands.contains(ac)) {
			str += Ships.valueOf(ac.toUpperCase()).getPrice();
		} else if (weaponCommands.contains(ac)) {
			str += Weapon.values()[weaponCommands.indexOf(ac)].getPrice();
		} else if (shieldCommands.contains(ac)) {
			str += Shield.values()[shieldCommands.indexOf(ac)].getPrice();
		} else if (gadgetCommands.contains(ac)) {
			str += Gadget.values()[gadgetCommands.indexOf(ac)].getPrice();
		} else if (ac.equals("fuel")) {
			str += ship.getShipType().getFuelCost() * (int) fuelSpinner.getValue();
		}
		lblTotal.setText(str);
	}
	
	/**
	 * for buyButtion Action perform
	 * @param ac
	 */
	private void buyButtonActionPerformed(String ac) {
		boolean check = true;
		if (shipCommands.contains(ac)) {
			check = imp.canBuyShip(Ships.valueOf(ac.toUpperCase()));
		} else if (weaponCommands.contains(ac)) {
			check = imp.canBuyWeapon(Weapon.values()[weaponCommands.indexOf(ac)]);
		} else if (shieldCommands.contains(ac)) {
			check = imp.canBuyShield(Shield.values()[shieldCommands.indexOf(ac)]);
		} else if (gadgetCommands.contains(ac)) {
			check = imp.canBuyGadget(Gadget.values()[gadgetCommands.indexOf(ac)]);
		} else if (ac.equals("fuel")) {
			check = imp.canBuyFuel((int) fuelSpinner.getValue());
		}
		if (!check) JOptionPane.showMessageDialog(this,
				imp.getErrorMsg(), "Failed to buy", JOptionPane.ERROR_MESSAGE);
	}
	
	/**
	 * for sell button
	 * @param ac
	 */
	private void sellButtonActionPerformed(String ac) {
		boolean check = true;
		if (shipCommands.contains(ac)) {
			JOptionPane.showMessageDialog(this,
					"You have to buy a new ship in " +
					"order to sell your current ship",
					"Failed to sell", JOptionPane.ERROR_MESSAGE);
		} else if (weaponCommands.contains(ac)) {
			check = imp.canSellWeapon(Weapon.values()[weaponCommands.indexOf(ac)]);
		} else if (shieldCommands.contains(ac)) {
			check = imp.canSellShield(Shield.values()[shieldCommands.indexOf(ac)]);
		} else if (gadgetCommands.contains(ac)) {
			check = imp.canSellGadget(Gadget.values()[gadgetCommands.indexOf(ac)]);
		} else if (ac.equals("fuel")) {
			JOptionPane.showMessageDialog(this, "You cannot sell fuel",
					"Failed to sell", JOptionPane.ERROR_MESSAGE);
		}
		if (!check) JOptionPane.showMessageDialog(this,
				imp.getErrorMsg(), "Failed to sell",
				JOptionPane.ERROR_MESSAGE);
	}

	/**
	 * update the price for the fuel with the updated amount
	 * @param e
	 */
	@Override
	public void stateChanged(ChangeEvent e) {
		if (rdbtnFuel.isSelected()) {
			// update the price for the fuel with the updated amount
			lblTotal.setText("Total: " + ship.getShipType().getFuelCost()
					* (int) fuelSpinner.getValue());
		}
	}
}
